//
//  UpdataAlertView.m
//  MeterMart
//
//  Created by ENERGY on 2018/11/2.
//  Copyright © 2018年 ENERGY. All rights reserved.
//

#import "MinusFiftyView.h"

@implementation MinusFiftyView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.alpha = 0;
        UIButton *backBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - BOTTOM_HEIGHT)];
        [backBtn addTarget:self action:@selector(hidden:) forControlEvents:UIControlEventTouchUpInside];
        backBtn.backgroundColor = [UIColor colorWithRed:0.2 green:0.2 blue:0.2 alpha:0.75];
        [self addSubview:backBtn];
        //图片背景
        UIImageView * bgImg = [[UIImageView alloc] init];
        bgImg.image = [UIImage imageNamed:@"minus"];
        [self addSubview:bgImg];
        //叉
        UIImageView * closeImg = [[UIImageView alloc] init];
        closeImg.image = [UIImage imageNamed:@"false"];
        [self addSubview:closeImg];
        //masonry
        __weak typeof (self)weakSelf = self;
        [bgImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(weakSelf.mas_top).mas_offset(36/WIDTH_6_SCALE);
            make.left.right.equalTo(weakSelf);
            make.bottom.equalTo(weakSelf.mas_bottom).mas_offset(-135/WIDTH_6_SCALE);
        }];
        [closeImg mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(weakSelf.mas_centerX);
            make.width.height.mas_offset(28/WIDTH_6_SCALE);
            make.top.equalTo(bgImg.mas_bottom).mas_offset(39/WIDTH_6_SCALE);
        }];
    }return self;
}

- (void)showView{
    [[UIApplication sharedApplication].delegate.window addSubview:self];
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 1;
    }];
}
- (void)updataBtnClick:(UIButton *)sender{
    NSLog(@"更新");
    [self cancelView];
}
- (void)hidden:(UIButton *)sender{
    NSLog(@"隐藏");
    [self cancelView];
}
- (void)cancelView{
    [UIView animateWithDuration:.15 animations:^{
        self.alpha = 0 ;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
@end
